#include "GameCore.h"

GameCore::_GameStatus GameCore::HuiHeKaiShiJiNeng(int player)
{
    //独秀技能
    if(m_arrayPlayer[player].containJiNeng(_JiNeng::JiNengValue_DuXiu))
    {
        m_strMsg = _T("%1开始")
                .arg(_JiNeng::getName(_JiNeng::JiNengValue_DuXiu));
        emit s_Message(m_strMsg);
        ShowChuPaiMessage(m_strMsg, 2000);


        m_arrayPlayer[player].m_nMoPaiJieDuan = -1;

        QString strMsg = _T("%1 技能触发")
                .arg(_JiNeng::getName(_JiNeng::JiNengValue_DuXiu));
        int arrayTime[] = {4000,3000,2000,1500,1000,900,800,700,600,500};
        int i = 0;
        //循环问题
        while(WenTi(player, strMsg, arrayTime[i]))
        {
            if(gameStatus() != Game_Status_Continue)return gameStatus();

            if(i < 9)i++;
            if(!MoPai(player,1))
            {
                emit s_Critical(_T("[!GameCore]HuiHeKaiShiChuLi ERROR!"));
                return setGameStatus(Game_Status_ERROR);
            }

            emit s_RefreshAllPokePosition();

            m_strMsg = m_hashGameMessage[_Pai::Value_All][2]
                    .arg(getPlayerShowName(player))
                    .arg(1);
            ShowChuPaiMessage(m_strMsg, 0);
        }
    }
    return gameStatus();
}

GameCore::_GameStatus GameCore::HuiHeJieShuJiNeng(int player)
{
    return gameStatus();
}

GameCore::_GameStatus GameCore::DiaoXueJiNeng(int n, int player, int player1, _Pai::_PaiValue v)
{
    if(m_arrayPlayer[player].containJiNeng(_JiNeng::JiNengValue_DaHangHaiShiDai))
    {
        if(player1 >= 0)
        {
            _GameButtonValue ret;
            ret = ChuPai(player,GameCore::Game_ChuPai_Type_JiNeng,_JiNeng::JiNengValue_DaHangHaiShiDai,-1,-1,0);
            if(ret == Game_Button_OK)
            {
                m_strMsg = _T("%1 技能触发")
                        .arg(_JiNeng::getName(_JiNeng::JiNengValue_DaHangHaiShiDai));
                if(WenTi(player, m_strMsg, 0) == true)
                {
                    if(gameStatus() != Game_Status_Continue)return gameStatus();

                    switch(ret = ChuPai(player1,GameCore::Game_ChuPai_Type_JiNeng,_JiNeng::JiNengValue_DaHangHaiShiDai,-1,-1,1))
                    {
                    case Game_Button_Cancel:
                        if(DiaoXue(1,player1,player,_Pai::Value_JiNeng_DaHangHaiShiDai) != Game_Status_Continue)return gameStatus();
                        break;
                    case Game_Button_OK:
                        QiPai(m_arrayPlayer[player1].qiShouPai(m_arrayStep[0].nSelectValue[0],false));
                        QiPai(m_arrayPlayer[player1].qiShouPai(m_arrayStep[0].nSelectValue[1],false));
                        m_arrayPlayer[player1].tiaoZhengShouPaiDui();

                        emit s_RefreshAllPokePosition();

                        m_strMsg = _T("%1弃2张手牌")
                                .arg(getPlayerShowName(player1));
                        emit s_Message(m_strMsg);
                        ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

                        break;
                    default:
                        emit s_Critical(_T("[!GameCore]JiNengValue_DaHangHaiShiDai1 ERROR:%1!").arg(ret));
                        return setGameStatus(Game_Status_ERROR);
                    }
                }
                else
                    if(gameStatus() != Game_Status_Continue)return gameStatus();
            }
            else if(ret == Game_Button_Cancel)
            {

            }
            else
            {
                emit s_Critical(_T("[!GameCore]JiNengValue_DaHangHaiShiDai2 ERROR:%1!").arg(ret));
                return setGameStatus(Game_Status_ERROR);
            }
        }
    }


    if(m_arrayPlayer[player].containJiNeng(_JiNeng::JiNengValue_ZuoYongLi))
    {
        if(player1 >= 0 && v == _Pai::Value_Sha)
        {
            QVariantList listJiNeng;
            listJiNeng << _JiNeng::JiNengValue_ZuoYongLi;
            _GameButtonValue ret;
            m_strMsg = _T("%1 技能发动")
                    .arg(_JiNeng::getName(_JiNeng::JiNengValue_ZuoYongLi));
            ret = ChuSha(player,1,1,listJiNeng,m_strMsg);

            if(ret == Game_Button_OK)
            {
                //ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

                Sha(player,player1,true,Game_ChuPai_Type_Pai);
                if(gameStatus() != Game_Status_Continue)return gameStatus();
            }
            else if(ret == Game_Button_Cancel)
            {

            }
            else
            {
                emit s_Critical(_T("[!GameCore]JiNengValue_ZuoYongLi ERROR:%1!").arg(ret));
                return setGameStatus(Game_Status_ERROR);
            }

        }
    }

    return gameStatus();
}

GameCore::_GameStatus GameCore::ChuShanJiNeng(int player, int player1)
{
    if(m_arrayPlayer[player].containJiNeng(_JiNeng::JiNengValue_JunShiTanDing))
    {
        m_strMsg = _T("%1 技能触发")
            .arg(_JiNeng::getName(_JiNeng::JiNengValue_JunShiTanDing));
        emit s_Message(m_strMsg);
        ShowChuPaiMessage(m_strMsg, 0);

        if(WenTi(player, m_strMsg, 0) == true)
        {
            //m_strMsg = m_hashGameMessage[_Pai::Value_All][6]
            //    .arg(getPlayerShowName(player));
            //emit s_Message(m_strMsg);
            //ShowChuPaiMessage(m_strMsg);
            DiaoXue(1,player1,player,_Pai::Value_Sha);
        }
        if(gameStatus() != Game_Status_Continue)return gameStatus();
    }


    return gameStatus();
}
